package com.tree.thread.pubsub;

import java.util.Random;

/**
 * @ClassName com.tree.thread.pubsub
 * <p>
 * 生产者
 * </p>
 * @Author tree
 * @Date 2019-11-02 15:53
 * @Version 1.0
 */
public class Producer implements Runnable {

    private Random random = new Random();
    private IStorage storage;

    public Producer(IStorage storage) {
        this.storage = storage;
    }


    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(random.nextInt(1000));
                storage.produce();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
